package com.gh.pattern.proxy.jdk;

import com.gh.pattern.proxy.staticed.Person;

import java.io.ObjectInputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKHuangniu implements InvocationHandler {

    private Person target;

    public Object getInstance(Person target) throws Exception {
        this.target = target;

        Class clazz = target.getClass();

        return Proxy.newProxyInstance(clazz.getClassLoader(),
                clazz.getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是黄牛，现在根据你给的要求给你抢票");
        method.invoke(this.target,args);
        System.out.println("我是黄牛，如果抢到的话会告诉你的");
        return null;
    }
}
